package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.ClazzMapper;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hu
 * @date 2025/3/4
 */
@Service
public class ClazzServiceImpl implements ClazzService {

    @Autowired
    private ClazzMapper clazzMapper;

    @Override
    public PageResult<Clazz> page(ClazzQueryParam queryParam) {
        //获取分页参数
        Integer page = queryParam.getPage();
        Integer pageSize = queryParam.getPageSize();
        //设置分页参数
        PageHelper.startPage(page, pageSize);
        //获取分页数据
        List<Clazz> clazzList = clazzMapper.list(queryParam);
        Page<Clazz> p = (Page<Clazz>) clazzList;
        return new PageResult<>(p.getTotal(), p.getResult());
    }

    @Override
    public void deleteById(Integer id) {
        clazzMapper.deleteById(id);
    }

    @Override
    public void addClazz(Clazz clazz) {
         clazzMapper.addClazz(clazz);
    }

    @Override
    public Clazz selById(Integer clazzId) {
        return clazzMapper.selById(clazzId);
    }

    @Override
    public void updateById(Clazz clazz) {
        clazzMapper.updateById(clazz);
    }

    @Override
    public List<Clazz> sel() {
        return clazzMapper.sel();
    }
}
